package club.xyes.zkh.ecommerce.service;

import club.xyes.zkh.ecommerce.commons.dto.Tuple2;
import club.xyes.zkh.ecommerce.commons.entity.Shop;
import club.xyes.zkh.ecommerce.commons.entity.User;
import club.xyes.zkh.ecommerce.commons.entity.UserMembership;
import club.xyes.zkh.ecommerce.commons.exception.DiscountException;
import club.xyes.zkh.ecommerce.service.adapter.UserMembershipSingleDependencyAdapter;

import java.util.List;

/**
 * Create by 郭文梁 2019/4/18 0018 14:44
 * UserMembershipService
 * 用户会员等级关系相关业务行为定义
 *
 * @author 郭文梁
 * @data 2019/4/18 0018
 */
public interface UserMembershipService extends BaseService<UserMembership>, UserMembershipSingleDependencyAdapter {
    /**
     * 根据用户ID查询会员等级
     *
     * @param userId 用户ID
     * @return GeneralResult
     */
    List<UserMembership> findByUserIdFetchAll(Integer userId);

    /**
     * 根据用户ID和商铺ID查询会员卡信息
     *
     * @param userId 用户ID
     * @param shopId 商铺ID
     * @return 会员卡信息
     */
    List<UserMembership> findByUserIdAndShopIdFetchAll(Integer userId, Integer shopId);

    /**
     * 检查用户是否为商家的会员
     *
     * @param user 用户
     * @param shop 商家
     * @return 是否为会员
     */
    boolean isMembership(User user, Shop shop);

    /**
     * 计算折扣价
     *
     * @param id   id
     * @param user 用户
     * @param shop 店铺
     * @param fee  应付金额
     * @return (会员定义 ， 折扣金额)
     * @throws DiscountException 指定的折扣方式存在逻辑错误
     */
    Tuple2<UserMembership, Integer> getDiscount(Integer id, User user, Shop shop, int fee) throws DiscountException;
}
